package com.googlecode.tracey.ui.demo;

import com.googlecode.utterlyidle.Response;
import com.googlecode.utterlyidle.annotations.*;

import static com.googlecode.funclate.Model.mutable.model;
import static com.googlecode.totallylazy.Bytes.bytes;
import static com.googlecode.utterlyidle.HttpHeaders.CONTENT_TYPE;
import static com.googlecode.utterlyidle.MediaType.TEXT_HTML;
import static com.googlecode.utterlyidle.ResponseBuilder.response;
import static com.googlecode.utterlyidle.Status.OK;
import static java.util.UUID.randomUUID;

@Path("demo-message-server")
public class DemoResource {

    @GET
    @Produces(TEXT_HTML)
    public Response searchForm() {
        return response().status(OK).header(CONTENT_TYPE, TEXT_HTML).entity(bytes(getClass().getResourceAsStream("DemoSearchForm.html"))).build();
    }

    @POST
    @Path("search")
    public String byTraceyIds(@FormParam("traceyId") String traceyId) {
        return model()
                .add("messages", model()
                        .add("from", "You")
                        .add("to", "Tracey")
                        .add("name", "HowDoYouWork? (Click Me)")
                        .add("body", "I really want to know")
                        .add("messageId", randomUUID().toString()))
                .add("messages",
                        model()
                                .add("from", "Tracey")
                                .add("to", "You")
                                .add("name", "ShortAnswer (Click Me)")
                                .add("body", "Create your Message Server, edit the generated ./config.json file, and restart Tracey with that config")
                                .add("messageId", randomUUID().toString()))

                .toString();
    }

}
